package com.zbkj.crmeb.merchant.api.controller;


import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.category.vo.CategoryTreeVo;
import com.zbkj.crmeb.chant.service.IChannelMerchantService;
import com.zbkj.crmeb.enums.StockAreaTempEnum;
import com.zbkj.crmeb.front.service.ProductService;

import com.zbkj.crmeb.store.request.StoreProductRuleSearchRequest;
import com.zbkj.crmeb.store.response.StoreProductRuleInformationResponse;
import com.zbkj.crmeb.store.service.ChannelCategoryConfigService;
import com.zbkj.crmeb.store.service.StoreProductRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 分类服务
 * @Description: 
 * @author daigb
 * @date 2021-04-16
 */
@RestController
@RequestMapping("api/front/mer")
@Api(tags = "分类服务")

public class FontCategoryController extends ApiBaseController {

    @Autowired
    private ProductService productService;

    @Autowired
    private IChannelMerchantService channelMerchantService;
    @Autowired
    private ChannelCategoryConfigService channelCategoryConfigService;
    @Autowired
    private StoreProductRuleService storeProductRuleService;

    /**
     * 获取分类
     * @author Mr.Zhang
     * @since 2020-06-03
     */
    @ApiOperation(value = "获取分类")
    @RequestMapping(value = "/category", method = RequestMethod.GET)
    public CommonResult<List<CategoryTreeVo>> getCategory(HttpServletRequest servletRequest){
        return CommonResult.success(channelCategoryConfigService.getFrontTreeByMerId(getMerId(servletRequest)));
        //return CommonResult.success(productService.getCategory());
    }

    @ApiOperation(value = "获取商户发货地")
    @GetMapping(value = "/stockArea")
    public CommonResult<List<StockAreaTempEnum>> getStockArea(HttpServletRequest servletRequest){
        return CommonResult.success(channelMerchantService.getStockArea(getMerId(servletRequest)));
    }

    /**
     * @param servletRequest
     * @return com.crmeb.core.common.CommonResult<java.util.List<com.zbkj.crmeb.category.vo.CategoryTreeVo>>
     */
    @ApiOperation(value = "获取商户已启用分类")
    @RequestMapping(value = "/getCategoryByMerId", method = RequestMethod.GET)
    public CommonResult<List<CategoryTreeVo>> getCategoryByMerId(HttpServletRequest servletRequest){
        return CommonResult.success(channelCategoryConfigService.getFrontTreeByMerId(getMerId(servletRequest)));
    }

    @ApiOperation(value = "根据分类获取规格信息和商品信息")
    @RequestMapping(value = "/getRuleByCate", method = RequestMethod.GET)
    public CommonResult<StoreProductRuleInformationResponse> getRuleByCate(@Validated StoreProductRuleSearchRequest request, HttpServletRequest servletRequest){
        return CommonResult.success(storeProductRuleService.getRuleByCate(request));
    }

}
